package com.lancoo.answer.view.dialog

import android.app.Dialog
import android.content.Context
import android.graphics.Typeface
import android.os.Bundle
import android.os.Handler
import android.view.Gravity
import android.widget.ImageView
import android.widget.RelativeLayout
import android.widget.TextView
import com.lancoo.answer.R
import com.lancoo.answer.util.LancooAnimUtils
import com.lancoo.answer.widget.FireworksView

class DialogLevelUp(
    context: Context?,
    val currLevel: Int
) : Dialog(context!!, R.style.CustomDialog) {
    /**
     * 提交按钮
     */
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.ev_dialog_level_up)
        window!!.setGravity(Gravity.CENTER) //设置弹窗右对齐
        window!!.setWindowAnimations(R.style.MyDialogScale) //设置动画效果

        //按空白处不能取消动画
        setCanceledOnTouchOutside(true)
        //初始化界面数据
        initView()

        Handler().postDelayed({
            dismiss()
        },3000)
    }

    fun initView() {

        val mViewGif = findViewById<FireworksView>(R.id.ViewGif)
        val mIvScoreBadge = findViewById<ImageView>(R.id.IvScoreBadge)
        val mRlLevelView = findViewById<RelativeLayout>(R.id.RlLevelView)
        val mTvLevelUpMessage = findViewById<TextView>(R.id.TvLevelUpMessage)
        mViewGif.setOnClickListener {
            dismiss()
        }
        if (currLevel == 0) {
            mIvScoreBadge.setImageResource(R.mipmap.ev_icon_rank_star_a)
        } else if (currLevel == 1) {
            mIvScoreBadge.setImageResource(R.mipmap.ev_icon_rank_star_b)
        } else if (currLevel == 2) {
            mIvScoreBadge.setImageResource(R.mipmap.ev_icon_rank_star_c)
        } else if (currLevel == 3) {
            mIvScoreBadge.setImageResource(R.mipmap.ev_icon_rank_star_d)
        }else if (currLevel == 4) {
            mIvScoreBadge.setImageResource(R.mipmap.ev_icon_rank_star_e)
        }
        LancooAnimUtils.startScaleBigAnim(context, mRlLevelView)
        mTvLevelUpMessage.typeface = Typeface.createFromAsset(context.assets, "fonts/cool_black.TTF")
        LancooAnimUtils.startVerticalScaleBigAnim(context, mTvLevelUpMessage)
    }

}